package com.itrus.cert.util;

import com.itrus.cert.KeyPairType;
import com.itrus.cryptorole.CryptoException;
import java.math.BigInteger;
import java.security.InvalidParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.interfaces.DSAKey;
import java.security.interfaces.DSAParams;
import java.security.interfaces.RSAKey;
import java.text.MessageFormat;
import javax.crypto.interfaces.DHKey;
import javax.crypto.spec.DHParameterSpec;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.DHKeyParameters;
import org.bouncycastle.crypto.params.DHParameters;
import org.bouncycastle.crypto.params.DSAKeyParameters;
import org.bouncycastle.crypto.params.DSAParameters;
import org.bouncycastle.crypto.params.RSAKeyParameters;

public final class KeyPairUtils
{
  public static KeyPair generateKeyPair(KeyPairType paramKeyPairType, int paramInt)
    throws CryptoException
  {
    try
    {
      KeyPairGenerator localKeyPairGenerator = KeyPairGenerator.getInstance(paramKeyPairType.name());
      localKeyPairGenerator.initialize(paramInt, SecureRandom.getInstance("SHA1PRNG"));
      KeyPair localKeyPair = localKeyPairGenerator.generateKeyPair();
      return localKeyPair;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new CryptoException(MessageFormat.format("Could not generate " + paramKeyPairType.name() + " key pair.", new Object[] { paramKeyPairType }), localNoSuchAlgorithmException);
    }
    catch (InvalidParameterException localInvalidParameterException)
    {
      throw new CryptoException(MessageFormat.format("Invalid parameter for a '" + paramInt + "' key pair.", new Object[] { paramKeyPairType }), localInvalidParameterException);
    }
  }

  public static int getKeyLength(PublicKey paramPublicKey)
    throws CryptoException
  {
    if ((paramPublicKey instanceof RSAKey))
      return ((RSAKey)paramPublicKey).getModulus().bitLength();
    if ((paramPublicKey instanceof DSAKey))
      return ((DSAKey)paramPublicKey).getParams().getP().bitLength();
    if ((paramPublicKey instanceof DHKey))
      return ((DHKey)paramPublicKey).getParams().getP().bitLength();
    throw new CryptoException("Could not get public key size.");
  }

  public static int getKeyLength(AsymmetricKeyParameter paramAsymmetricKeyParameter)
    throws CryptoException
  {
    if ((paramAsymmetricKeyParameter instanceof RSAKeyParameters))
      return ((RSAKeyParameters)paramAsymmetricKeyParameter).getModulus().bitLength();
    if ((paramAsymmetricKeyParameter instanceof DSAKeyParameters))
      return ((DSAKeyParameters)paramAsymmetricKeyParameter).getParameters().getP().bitLength();
    if ((paramAsymmetricKeyParameter instanceof DHKeyParameters))
      return ((DHKeyParameters)paramAsymmetricKeyParameter).getParameters().getP().bitLength();
    throw new CryptoException("Could not get public key size.");
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.cert.util.KeyPairUtils
 * JD-Core Version:    0.6.2
 */